
<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
<link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
	<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>

<div class="panel ">
	<div class="panel-body pan" style="height: 525px">
	<div class="form-body pal">
		<div class="row" style="margin-top:-15px; margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; height: 60px;float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">中文名称
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="nameZh" type="text" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px;height: 60px; float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">英文名称
					<span class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="nameEn" type="text" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6" 
				style="width: 400px;height: 60px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">封面图片
				</label>
				<div class="col-md-9">
					<div>
						<div style="display:inline " id="single"></div>
						<input type="button" style="width: 70px;height: 30px;padding: 0;background-color: #4cae4c;border-color: #4cae4c;" class="btn btn-primary" onclick="upImages()" value="上传图片"  />
						<textarea id="uploadImage" name="uploadImage"></textarea>
						<input id="cover" type="hidden" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px;height: 60px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">所属分类<span
				class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
						<input id="categoryNmae" type="text" placeholder="请选择所属分类" class="form-control" disabled="true" /> 
						<span class="input-group-btn">
						<button onclick="getCategory()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
						</span> 
						<input id="categoryId" type="hidden" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
			 	style="width: 400px;height: 60px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">状态
				<span class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="status" class="form-control">
							<option value="0">正常</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
			</div>
			<div class="col-lg-6"
			 	style="width: 400px;height: 60px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">是否推荐
				<span class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="recommend" class="form-control">
							<option value="0">否</option>
							<option value="1">是</option>
						</select>
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px;height: 60px; float:left;  margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">排序
					<span class='require' >*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="sort" type="text" class="form-control" />
					</div>
				</div>
			</div>
		</div>
		<div>
			<label for="inputUsername" class="col-md-3 control-label">描述
				<span class='require'></span> </label>
			<div class="col-md-12">
				<div class="input-icon">
					<textarea id="description"  rows="5" cols="20" class="form-control" ></textarea> 
				</div>
			</div>
		</div>
		<input id="id" type="hidden" class="form-control" />
	</div>
</div>
<?} ?>
<script>
	var id = window.parent.getId();
	var curr = window.parent.getCurr();
	var _editor;
	$(function() {
		if (id != 0) {
			demo();
		}
		 _editor = UE.getEditor('uploadImage');
	    _editor.ready(function (){
	        //设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
	        _editor.setDisabled();
	        //隐藏编辑器,因为只使用上传功能
	        _editor.hide();
	        //侦听图片上传
	  	 	_editor.addListener('beforeInsertImage',function(t,arg){
	  	 			for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].src;
	  	 				$("#cover").val(urlPath);
						$("#single").html("<img src='"+urlPath+"' width='30' height='30' />");
	  	 			}
	        });
	        //侦听文件上传
		   	 _editor.addListener('afterUpfile',function(t,arg){
		   	 	
		   	 });
	   }); 
	});
	//上传图片
	function upImages() {
		var myFiles = _editor.getDialog("insertimage");
	  		myFiles.open();
	   
	}
	//所属分类
	function getCategory() {
		parent.layer.open({
			type : 2,
			area : [ '900px', '650px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"分类",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["community-knowledge-category.html?winName="+window.name, 'no'],
			yes : function(index,layer) {		
			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  			  iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	function Page() {
		if ($.trim($("#nameZh").val()).length < 1) {
			alert('中文名称不能为空！');
			return null;
		}
		if ($.trim($("#categoryId").val()).length < 1) {
			alert('所属分类不能为空！');
			return null;
		}
		if ($.trim($("#nameEn").val()).length < 1) {
			alert('英文名称不能为空！');
			return null;
		}else{
			var reg = /^[a-zA-Z ]+$/;  
			    if (!reg.test($("#nameEn").val())) {  
			        alert('请输入正确的英文名称！');
			        $("#nameEn").val("");
					return null;
			    } 
		}
		if ($.trim($("#sort").val()).length < 1) {
			alert('排序不能为空！');
			return null;
		}else{
			 var reg = /^[0-9]*$/;  
			    if (!reg.test($("#sort").val())) {  
			        alert('排序只能为正整数！');
			        $("#sort").val("");
					return null;
			    }  
		}
		$.ajax({
			type : "post",
			url : "addOrUploadCommunityKnowledge.do",
			data : {
				"id" : id,
				"nameZh" : $("#nameZh").val(),
				"nameEn" : $("#nameEn").val(),
				"sort" : $("#sort").val(),
				"description" : $("#description").val(),
				"status" : $("#status").val(),
				"categoryId" : $("#categoryId").val(),
				"cover" : $("#cover").val(),
				"recommend" : $("#recommend").val(),
			},
			dataType : "json",
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				if(data[0].data == 'yes'){
					window.parent.demo(curr);
					parent.layer.msg('提交成功');
					parent.layer.close(index);
				}else{
					parent.layer.msg('提交失败！请检查数据是否正确！');
				}
			},
			error : function(data) {
				parent.layer.msg('提交失败！请检查数据是否正确！');
			}
		});
	}
	function demo() {
		$.getJSON('findCommunityKnowledge.do', {
			id : id
		//向服务端传的参数，此处只是演示
		}, function(res) {
			//此处仅仅是为了演示变化的内容
			$("#nameZh").val(res[0].nameZh);
			$("#nameEn").val(res[0].nameEn);
			$("#description").val(res[0].description);
			$("#status").val(res[0].status);
			$("#sort").val(res[0].sort);
			$("#id").val(res[0].id);
			$("#categoryId").val(res[0].categoryId);
			$("#categoryNmae").val(res[0].categoryName);
			$("#recommend").val(res[0].recommend);
			$("#cover").val(res[0].cover);
			$("#single").html(res[0].imges);
		});
	};
</script>
